package com.chzc.fm.duotin.ui.more;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Window;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.bean.more.RecommendBean;
import com.chzc.fm.duotin.ui.more.util.MoreUtil;
import com.chzc.fm.duotin.utils.DuotinTask;
import com.chzc.fm.duotin.utils.GlobalParam;
import com.chzc.fm.duotin.utils.HttpUtil;
import com.chzc.fm.duotin.utils.Unicode2CN;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class RecommendApp extends Activity {
    private RecyclerView mRecyclerView;
    public MyRecommendAdapter mAdapter;
    public List<Recommend_Application> applicationsdata;
    protected void onCreate(Bundle savedInstanceState)
    {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recommend_app);
        mRecyclerView=(RecyclerView)findViewById(R.id.recommendApp_recyclerview);
        applicationsdata=new ArrayList<Recommend_Application>();
        initdata();

        //mRecyclerView = (RecyclerView) findViewById(R.id.recommendApp_recyclerview);
        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        //设置适配器

        mAdapter = new MyRecommendAdapter(this,applicationsdata);
        mRecyclerView.setAdapter(mAdapter);


    }
    private void initdata(){
        Recommend_Application app[]=new Recommend_Application [6];
        app[0]=new Recommend_Application();
        app[0].setTextView1("爱奇艺视频");
        app[0].setTextView2("高清首播《我是特种兵3》《咱们结婚吧》等热剧，新版频道升级，跟卡顿说再见~");
        app[0].setImageleft(R.drawable.ic_album_item_download_nomal);
        app[0].setImageright(R.drawable.ic_default_app);
        applicationsdata.add(app[0]);
        app[1]=new Recommend_Application();
        app[1].setTextView1("美咖相机");
        app[1].setTextView2("自拍美颜，一键化妆，超多彩妆工具玩起来！~");
        app[1].setImageleft(R.drawable.ic_album_item_download_nomal);
        app[1].setImageright(R.drawable.ic_default_app);
        applicationsdata.add(app[1]);
        app[2]=new Recommend_Application();
        app[2].setTextView1("心里FM");
        app[2].setTextView2("心情不好的时候，听听心里FM。");
        app[2].setImageleft(R.drawable.ic_album_item_download_nomal);
        app[2].setImageright(R.drawable.ic_default_app);
        applicationsdata.add(app[2]);
        app[3]=new Recommend_Application();
        app[3].setTextView1("穿衣助手");
        app[3].setTextView2("发誓让你更懂搭配的应用");
        app[3].setImageleft(R.drawable.ic_album_item_download_nomal);
        app[3].setImageright(R.drawable.ic_default_app);
        applicationsdata.add(app[3]);
        app[4]=new Recommend_Application();
        app[4].setTextView1("曝曝");
        app[4].setTextView2("查工资，比公司，尽在曝曝");
        app[4].setImageleft(R.drawable.ic_album_item_download_nomal);
        app[4].setImageright(R.drawable.ic_default_app);
        applicationsdata.add(app[4]);
        app[5]=new Recommend_Application();
        app[5].setTextView1("途虎养车");
        app[5].setTextView2("途虎养车");
        app[5].setImageleft(R.drawable.ic_album_item_download_nomal);
        app[5].setImageright(R.drawable.ic_default_app);
        applicationsdata.add(app[5]);

        DuotinTask.IRequest request = new DuotinTask.IRequest() {
            @Override
            public Object doRequest() {
                return Unicode2CN.unicode2GBK((String) HttpUtil.doGet(MoreUtil.getRecommend()));
            }
        };

        DuotinTask.IRequestCallback callback = new DuotinTask.IRequestCallback() {
            @Override
            public void success(Object object) {
                try {
                    JSONObject root = new JSONObject(object.toString());
                    String msg = root.getString("error_msg");
                    if(GlobalParam.SUCCESS.equals(msg.toLowerCase())){
                        JSONArray array = root.getJSONArray("data");
                        List<RecommendBean> recommendBeanList = RecommendBean.arrayRecommendAppFromData(array.toString());

                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void error(String msg) {

            }
        };

        DuotinTask task = new DuotinTask(request, callback);
        task.execute();

    }



}






